<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <head th:include="common :: header"></head>
    <!--Font Awesome [ OPTIONAL ]-->
    <link th:href="@{/assets/css/magic-check.min.css}" rel="stylesheet">
</head>

<body>
<div id="page-content">

    <div class="row">
        <div class="col-lg-12">
            <div class="panel">
                <form id="dataForm" class="form-horizontal" th:action="@{${action}}" method="post">
                    <div class="panel-body">
                        <p class="text-main text-bold">为【[[${target.name}]]】分配权限</p>
                        <hr>
                        <div class="form-group">
                            <ul id="tree" class="ztree" style="width:230px; overflow:auto;"></ul>
                        </div>
                    </div>
                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-sm-12">
                                <button id="save-btn" class="btn btn-primary" type="button">提交</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>



</div>
<!-- END SETTINGS -->
<div th:include="common :: script"></div>
<script type="text/javascript" th:inline="javascript" >
    $(function() {

        var zNodes = [[${zTreeNodes}]];
        var zTreeObj = $.freedom.ui.tree.init("tree", JSON.parse(zNodes));

        $("#save-btn").on("click", function() {

            var permissionIdArr = [];
            var nodes = zTreeObj.getCheckedNodes(true);
            for(var i=0,len=nodes.length; i<len; i++) {
                permissionIdArr.push(nodes[i].id);
            }

            var param = {
                "roleId": [[${target.id}]],
                "permissionIdStr": permissionIdArr.join(",")
            };

            /**
             * 参数一：url   请求地址
             * 参数二：data  obj 类型数据
             * 参数三：fn    回调函数
             */
            $.freedom.action.request(document.getElementsByTagName("form")[0].action, param, function(resp) {
                $.freedom.modal.msg(resp.msg, 1, function() {
                    window.parent.$.freedom.modal.closeAll();
                    window.parent.$.freedom.ui.table.refreshData();
                });
            });
        });

    });
</script>
</body>
</html>
